
<%@ page import="com.medranocg.gd.Document" %>
<script>
	function loadAnotherVersion(documentId) {
		$('#detalleDocumentoModal').load("${createLink(controller:'consultaDocumentos', action:'modalShow')}",
				"id=" + documentId)

		return false
	}

	function anular(documentId) {
		$('#detalleDocumentoModal').load("${createLink(controller:'consultaDocumentos', action:'anular')}",
				"id=" + documentId)

		return false
	}
</script>

<div class="modal-dialog">
	<div class="modal-content">

		<div class="modal-header">
			<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		</div>

		<div class="modal-body">
			<g:form role="form" method="POST">
				<g:if test="${documentInstance.deleteDate}">
					<div class="alert alert-success">
						El documento ha sido eliminado.
					</div>
				</g:if>
				<g:else>
				<g:if test="${!documentInstance.lastVersion }">
					<div class="alert alert-warning">
						La versi&oacute;n de este documento que usted est&aacute; viendo ha sido reemplazada por otras posteriores.
					</div>
				</g:if>

				<div class="form-group">
					<label for="customer">Cliente</label>
					<div style="height:auto" class="form-control">${documentInstance.customer.idPersona} (${documentInstance.customer.name}, CUIT: ${documentInstance.customer.cuit})</div>
				</div>

				<div class="form-group">
					<label for="documentType">Tipo de Documento</label>
					<div style="height:auto" class="form-control"><g:fieldValue bean="${documentInstance}" field="documentType"/></div>
				</div>
<%--
				<div class="form-group">
					<label for="name">Nombre</label>
					<div class="form-control"><g:fieldValue bean="${documentInstance}" field="name"/></div>
				</div>
 --%>
				<div class="form-group">
					<label for="purgeable">
						<input type="checkbox" id="purgeable" ${documentInstance.documentType.purgeable ? 'checked="checked"' : '' } onclick="return false" /> Expurgable
					</label>
				</div>

				<g:if test="${documentInstance.documentType.versionable }">
					<div class="form-group">
						<label for="version">Versi&oacute;n</label>
						<div class="form-control">${documentInstance.realVersion}</div>
					</div>
				</g:if>

				<div class="form-group">
					<label for="box">Caja</label>
					<div class="form-control">${documentInstance.box.cajaId}</div>
				</div>

				<div class="form-group">
					<label for="validTo">Fecha de vencimiento</label>
					<div class="form-control"><g:formatDate date="${documentInstance.validTo}" format="dd/MM/yyyy" /></div>
				</div>

				<g:if test="${documentInstance.notes}">
					<div class="form-group">
						<label for="notes">Notas</label>
						<div style="height:auto" class="form-control"><g:fieldValue bean="${documentInstance}" field="notes"/></div>
					</div>
				</g:if>

			<g:if test="${documentInstance.documentType.versionable}">
				<table class="table table-striped">
					<thead>
						<tr>
							<th>Versi&oacute;n</th>
							<th>Fecha</th>
							<th>Usuario</th>
							<th></th>
						</tr>
					</thead>
					<tbody>
						<g:each in="${listVersion}" status="i" var="version">
							<tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
								<td>
									<g:if test="${version.lastVersion }">
										${version.realVersion} (&Uacute;ltima)
									</g:if>
									<g:else>
										${version.realVersion}
									</g:else>
								</td>
								<td>
									<g:formatDate date="${version.createdDate}" format="dd/MM/yyyy" />
								</td>
								<td>
									${version.createdByUserName}
								</td>
								<td>
									<button type="button" class="btn btn-default" onclick="previewDocument('${version.id}')"><span class="glyphicon glyphicon-eye-open"></span></button>
									<a href="#" onclick="return loadAnotherVersion('${version.id}')" class="btn btn-default"><span class="glyphicon glyphicon-info-sign"></span></a>
								</td>
							</tr>
						</g:each>
					</tbody>
				</table>
			</g:if>
			</g:else>

			</g:form>			
		</div>

		<div class="modal-footer">
			<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
			<g:if test="${!documentInstance.deleteDate && documentInstance.lastVersion }">
				<a href="${createLink(controller:'corregirDocumentos', action:'index', id: documentInstance.id) }" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span> Corregir</a>
				<a href="#" onclick="return anular('${documentInstance.id}')" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span> Borrar</a>
			</g:if>
		</div>

	</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->

<script>
	$("#detalleDocumentoModal").scrollTop(0)
</script>
